<?php
/* -------------------------------------------------------------------------------------
* 	ID:						$Id: image_processing_step.php 11 2013-09-21 11:43:11Z phone.mueller@googlemail.com $
* 	Letzter Stand:			$Revision: 11 $
* 	zuletzt geaendert von:	$Author: siekiera $
* 	Datum:					$Date: 2013-09-21 11:43:11 +0000 (Sat, 21 Sep 2013) $
*
* 	SEO:mercari by Siekiera Media
* 	http://www.seo-mercari.de
*
* 	Copyright (c) since 2011 SEO:mercari
* --------------------------------------------------------------------------------------
* 	based on:
* 	(c) 2000-2001 The Exchange Project  (earlier name of osCommerce)
* 	(c) 2002-2003 osCommerce - www.oscommerce.com
* 	(c) 2003     nextcommerce - www.nextcommerce.org
* 	(c) 2005     xt:Commerce - www.xt-commerce.com
*
* 	Released under the GNU General Public License
* ----------------------------------------------------------------------------------- */

defined( '_VALID_XTC' ) or die( 'Direct Access to this location is not allowed.' );

define('MODULE_STEP_IMAGE_PROCESS_TEXT_DESCRIPTION', 'Imageprocessing - Stapelverarbeitung step-by-step Variante B');
define('MODULE_STEP_IMAGE_PROCESS_TEXT_TITLE', 'Imageprocessing-New (step-by-step Variante B)');
define('MODULE_STEP_IMAGE_PROCESS_STATUS_DESC','Modulstatus');
define('MODULE_STEP_IMAGE_PROCESS_STATUS_TITLE','Status');
define('IMAGE_EXPORT','Dr&uuml;cken Sie Ok um die Stapelverarbeitung zu starten, dieser Vorgang kann einige Zeit dauern, auf keinen Fall unterbrechen!.');
define('IMAGE_EXPORT_TYPE','<hr noshade><b>Stapelverarbeitung:</b>');

class image_processing_step {
    var $code, $title, $description, $enabled, $db;

    function __construct() {
		global $order, $db;

		$this->code = 'image_processing_step';
		$this->title = MODULE_STEP_IMAGE_PROCESS_TEXT_TITLE;
		$this->description = MODULE_STEP_IMAGE_PROCESS_TEXT_DESCRIPTION;
		$this->sort_order = MODULE_STEP_IMAGE_PROCESS_SORT_ORDER;
		$this->enabled = ((MODULE_STEP_IMAGE_PROCESS_STATUS == 'True') ? true : false);
		$this->db = $db;
    }

    function process($file, $offset) {
	    include ('includes/classes/'.FILENAME_IMAGEMANIPULATOR);
        @set_time_limit(0);
        $files=array();
        if($dir = opendir(DIR_FS_CATALOG_ORIGINAL_IMAGES)){
            while($file = readdir($dir)) {
                 if (is_file(DIR_FS_CATALOG_ORIGINAL_IMAGES.$file) and ($file !="index.html") and (strtolower($file) != "thumbs.db")){
                     $files[]=array('id' => $file, 'text' =>$file);
                 }
             }
        	closedir($dir);
        }
	    $step = 10;
	    $max_files = sizeof($files);
	    $limit = $offset + $step;
	    for($i=$offset; $i<$limit; $i++) {
			if ($i >= $max_files)
				redirect(href_link(FILENAME_MODULE_EXPORT, 'set=' . $_GET['set'] . '&module=image_processing_step'));

			$products_image_name = $files[$i]['text'];
			if ($files[$i]['text'] != 'Thumbs.db' && $files[$i]['text'] != 'Index.html') {
				require(DIR_WS_INCLUDES . 'product_thumbnail_images.php');
				require(DIR_WS_INCLUDES . 'product_info_images.php');
				require(DIR_WS_INCLUDES . 'product_popup_images.php');
			}
	    }
	    redirect(href_link(FILENAME_MODULE_EXPORT, 'set=' . $_GET['set'] . '&action=save&module=image_processing_step&start=' . $limit));
    }

    function display() {
    	return array('text' =>
                            IMAGE_EXPORT_TYPE.'<br>'.
                            IMAGE_EXPORT.'<br>'.
                            '<br>' . button(BUTTON_REVIEW_APPROVE) . '&nbsp;' .
                            button_link(BUTTON_CANCEL, href_link(FILENAME_MODULE_EXPORT, 'set=' . $_GET['set'] . '&module=image_processing_step')));
    }

    function check() {
		if (!isset($this->_check)) {
			$check = $this->db->db_query("SELECT configuration_value from " . TABLE_CONFIGURATION . " WHERE configuration_key = 'MODULE_STEP_IMAGE_PROCESS_STATUS'");
			$this->_check = $check->_numOfRows;
		}
		return $this->_check;
    }

    function install() {
		$this->db->db_query("INSERT INTO " . TABLE_CONFIGURATION . " (configuration_key, configuration_value,  configuration_group_id, sort_order, set_function, date_added) VALUES ('MODULE_STEP_IMAGE_PROCESS_STATUS', 'True',  '6', '1', 'cfg_select_option(array(\'True\', \'False\'), ', now())");
	}

    function remove() {
		$this->db->db_query("DELETE FROM " . TABLE_CONFIGURATION . " WHERE configuration_key in ('" . implode("', '", $this->keys()) . "')");
    }

    function keys() {
		return array('MODULE_STEP_IMAGE_PROCESS_STATUS');
    }
}
?>